package com.shengqin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shengqin.common.pojo.CommonPage;
import com.shengqin.entity.SummaryArchive;
import com.shengqin.entity.SummaryGraduation;
import com.shengqin.mapper.SummaryGraduationMapper;
import com.shengqin.pojo.summary.GraduationQueryParam;
import com.shengqin.service.ISummaryArchiveService;
import com.shengqin.service.ISummaryGraduationService;
import org.springframework.stereotype.Service;

@Service
public class SummaryGraduationServiceImpl extends ServiceImpl<SummaryGraduationMapper, SummaryGraduation> implements ISummaryGraduationService {
    @Override
    public Page<SummaryGraduation> getPage(CommonPage<GraduationQueryParam> pageParam) {
        QueryWrapper<SummaryGraduation> queryWrapper = new QueryWrapper<>();
        GraduationQueryParam graduationQueryParam = pageParam.getQueryParam();
        if (StrUtil.isNotEmpty(graduationQueryParam.getStudyCode())) {
            queryWrapper.lambda().eq(SummaryGraduation::getStudyCode,graduationQueryParam.getStudyCode());
        }
        if (StrUtil.isNotEmpty(graduationQueryParam.getName())) {
            queryWrapper.lambda().eq(SummaryGraduation::getName,graduationQueryParam.getName());
        }
        if (StrUtil.isNotEmpty(graduationQueryParam.getSchoolName())) {
            queryWrapper.lambda().eq(SummaryGraduation::getSchoolName,graduationQueryParam.getSchoolName());
        }
        if (graduationQueryParam.getFlag() != null) {
            queryWrapper.lambda().eq(SummaryGraduation::getFlag,graduationQueryParam.getFlag());
        }
        if (graduationQueryParam.getMinScore()!= null) {
            queryWrapper.lambda().ge(SummaryGraduation::getScore,graduationQueryParam.getMinScore());
        }
        if (graduationQueryParam.getMaxScore()!= null) {
            queryWrapper.lambda().le(SummaryGraduation::getScore,graduationQueryParam.getMaxScore());
        }
        if (StrUtil.isNotEmpty(graduationQueryParam.getSchoolYear())) {
            queryWrapper.lambda().eq(SummaryGraduation::getSchoolYear,graduationQueryParam.getSchoolYear());
        }
        queryWrapper.lambda().orderByDesc(SummaryGraduation::getId);
        Page<SummaryGraduation> page = new Page<>(pageParam.getPageNo(),pageParam.getPageSize());
        page(page,queryWrapper);
        return page;
    }
}
